#include "Router.h"		

Router::Router()
{

	unsigned char i = 0;
	for(i = 0; i < 8; i++)
	{
		routedBytes[i] = 0;
		routedBits[i] = i;
	}
	routee = NULL;
}
//assigns the routee byte.
Router::Router(volatile unsigned char* r)
{
	routedBytes[8] = 0;
	unsigned char i = 0;
	routee = r;
	for(i = 0; i < 8; i++)
	{
		routedBytes[i] = GetBit(*routee, i);
		routedBits[i] = i;
	}
	routee = NULL;
}
//get the routee byte
volatile unsigned char* Router::getRoutee()
{
	return routee;
}

//sets the routee byte
void Router::setRoutee(volatile unsigned char* r)
{
	routee = r;
}

//route bit
void Router::routeBit(unsigned char routeeBit, unsigned char routerByte)
{
	routedBits[routerByte] = routeeBit;
}

//get the routed bit gets a pointer to the routed bits.
unsigned char* Router::getRoutedBit(unsigned char routeeNumber)
{
	return &(routedBytes[routedBits[routeeNumber]]);
}

//get a bit pointer to the routee bit.
BitPointer Router::getRouteeBitPointer(unsigned char routeeNumber)
{
	BitPointer pointer = BitPointer(routee, routeeNumber);
	return pointer;
}

//get a bit pointer to the routed bit.
BitPointer Router::getRoutedBitPointer(unsigned char routeeNumber)
{
	BitPointer pointer = BitPointer(&(routedBytes[routedBits[routeeNumber]]),
					0); //assumes always routed to zero bit.
	return pointer;
}

//runs the router and sets and gets the values accordingly.
void Router::run()
{
	unsigned char i = 0;
	for(i = 0; i < 8; i++)
	{
		unsigned char RoutedValue = GetBit(routededBytes[i], 0);
		unsigned char RouteeValue = GetBit(*routee, routedBits[i]);
		//assign the RoutedValue to the Routee
		*routee = SetBit(*routee, i, RoutedValue);
		//assign the RouteeValue to the routedBytes.
		routedBytes[i] = SetBit(routedBytes[i], 0, RouteeValue);
		//I have gotten both values and set both values accordingly.
	}
}

